package com.six.firstpage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.core.entity.Zone;
import com.six.core.vo.Result;
import com.six.firstpage.service.ZoneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.coyote.OutputBuffer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:zzh
 * @create: 2023-02-28 10:08
 * @Description:
 */
@Api(value = "firstpage/zone", tags = {"专区管理后台接口"})
@RestController
@RequestMapping("firstpage/zone")
public class ZoneController {

    @Autowired
    private ZoneService zoneService;

    @GetMapping("/getAllZone")
    public Result getAllZone() {
        List<Zone> allZone = zoneService.getAllZone();
        return new Result(2000,"查询专区成功",allZone);
    }
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "name", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "status", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "current", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = false)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("getZoneByName/{current}/{pageSize}")
    public Page<Zone> getZoneByName(String name, @RequestParam(defaultValue = "0") Integer status, @PathVariable @RequestParam(defaultValue = "1") Integer current, @PathVariable  @RequestParam(defaultValue = "5") Integer pageSize ){
        return zoneService.getZoneByName(name,status,current,pageSize);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Zone", name = "zone", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("addZone")
    public Integer addZone(@RequestBody Zone zone){
        return zoneService.addZone(zone);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Zone", name = "zone", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "PUT")
    @PutMapping("updateZone")
    public Integer updateZone(@RequestBody Zone zone){
        return zoneService.updateZone(zone);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("delZone/{id}")
    public Integer delZOne(@PathVariable Integer id){
        return zoneService.delZone(id);
    }

}
